﻿using System;
using System.Collections.Generic;
using System.Text;
using FunctionalCLR.Core;

namespace FunctionalCLR.Core.Function.List {

    /// <summary>
    /// lst = [1,3,5,7,9,10];
    /// element = select(lst, 3);
    /// echo(element);
    /// 
    /// the expected result is 5
    /// </summary>
    public class ListTakeNode : FuncNode {

        public ListTakeNode()
            : base() {
            this.Value = "select";
        }

        public override FuncNode GetReversedFunction(int index) {
            throw new NotImplementedException();
        }

        public override object Evaluate() {
            ListNode node = (ListNode)Children[1].Evaluate();
            int nth = Convert.ToInt32(Children[0].Evaluate());

            return node.Children[nth];
        }
    }
}
